package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.basedoc.model.Room;
import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.CheckIn;
import com.eling.elcms.travel.model.RoomRegister;
import com.eling.elcms.travel.model.view.*;
import com.eling.elcms.travel.service.IRoomRegisterManager;
import com.eling.elcms.travel.service.IRoomStatisticsManager;
import com.eling.elcms.travel.service.IRoomdStatisticsManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
public class RoomRegisterController extends BaseFormController {

	@Autowired
	private IRoomRegisterManager roomRegisterM;
	
	@Autowired
	private IRoomdStatisticsManager iRoomdStatisticsManager;
	
	@Autowired
	private IRoomStatisticsManager roomStatisticsManager;
	

	@RequestMapping("/api/roomregister/save")
	@ResponseBody
	public RoomRegister save(@ModelAttribute @ModelFilling RoomRegister cond) {
		return roomRegisterM.save(cond);
	}

	@RequestMapping("/api/roomregister/{pkRoomRegister}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkRoomRegister) {
		roomRegisterM.remove(pkRoomRegister);
		return new Msg("删除成功");
	}
	
	@RequestMapping("/api/roomregister/query")
	@ResponseBody
	public List<RoomRegister> query(@ModelAttribute RoomRegister cond) {
		return roomRegisterM.query(cond);
	}

	@RequestMapping("/api/roomregister/search*")
	@ResponseBody
	public List<RoomRegister> search(@ModelAttribute SearchCondition sc, @ModelAttribute RoomRegister cond) {
		sc.setQueryCondition(cond);
		return roomRegisterM.search(sc);
	}

	@RequestMapping("/api/roomregister/confirm")
	@ResponseBody
	public RoomRegister confirm(@ModelAttribute @ModelFilling RoomRegister cond) {
		return roomRegisterM.confirm(cond);
	}

	@RequestMapping("/api/roomregister/querymeter")
	@ResponseBody
	public List<RoomRegister> queryMeter(@RequestParam(name = "pkCheckInImplement")Long pkCheckInImplement) {
		return roomRegisterM.queryMeter(pkCheckInImplement);
	}

	@RequestMapping("/api/roomregister/savemeter")
	@ResponseBody
	public RoomRegister saveMeter(@ModelAttribute RoomRegister cond) {
		return roomRegisterM.saveMeter(cond);
	}
	
	/**
	 * 房态调整列表查询
	 * @param cond
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/roomregister/queryroombystatus")
	@ResponseBody
	public List<Room> queryRoomByStatus(@ModelAttribute Room cond){
		return roomRegisterM.queryRoomByStatus(cond);
	}

	/**
	 * 组团预约房态查询
	 * @param cond
	 * @return
	 * @author linjizeng
	 */
	@RequestMapping("/api/roomregister/queryroomstatus")
	@ResponseBody
	public List<RoomStatusView> queryRoomStatus(@ModelAttribute Room cond,
			@RequestParam(name = "startDate", required = false) Date startDate,
			@RequestParam(name = "endDate", required = false) Date endDate){
		return roomRegisterM.queryRoomStatus(cond,startDate,endDate);
	}
	
	/**
	 * 落实所有房间配置（老人团）
	 * @param pkCheckInImplement
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/roomregister/updatestatus")
	@ResponseBody
	public RoomRegister updateStatus(
			@RequestParam(name = "pkCheckInImplement", required = false) Long pkCheckInImplement) {
		return roomRegisterM.updateStatus(pkCheckInImplement);
	}

	
	/**
	 * 当日房态统计
	 */

	@RequestMapping("/api/roomstatistics/query")
	@ResponseBody
	public List<Room> query(@ModelAttribute Room cond){
		return iRoomdStatisticsManager.query(cond);
	}
	
	@RequestMapping("/api/roomstatistics/queryroomsum")
	@ResponseBody
	public List<RoomdStatisticsView> queryT(@ModelAttribute CheckIn cond){
		return iRoomdStatisticsManager.queryT(cond);
	}
	
	/**
	 * 入住类型收入统计
	 */
	@RequestMapping("/api/roomstatistics/querybyroomtype")
	@ResponseBody
	public List<IncomingByRoomTypeView> queryByRoomType(@RequestParam(value="startDate")Date startDate,
								@RequestParam(value="endDate")Date endDate){
		
		return roomStatisticsManager.queryByRoomType(startDate,endDate);
	}
	
	@RequestMapping("/api/roomstatistics/querybyroomtypedetails")
	@ResponseBody
	public List<IncomingDetailsView> queryByRoomTypeDetails(@RequestParam(value="startDate")Date startDate,
										@RequestParam(value="endDate")Date endDate,
										@RequestParam(value="checkinType")String checkinType){
		return roomStatisticsManager.queryByRoomTypeDetailes(checkinType,startDate,endDate);
	}
	
	@RequestMapping("/api/roomstatistics/querybytype")
	@ResponseBody
	public List<IncomingStatisticsView> queryByType(@RequestParam(value="startDate")Date startDate,
						@RequestParam(value="endDate")Date endDate){
		
		return roomStatisticsManager.queryByType(startDate,endDate);
	}
	@RequestMapping("/api/roomstatistics/querybytypedetails")
	@ResponseBody
	public List<IncomingTypeDetailsView> queryByTypeDetails(@RequestParam(value="startDate")Date startDate,
							@RequestParam(value="endDate")Date endDate,
							@RequestParam(value="pkRoomType")Long pkRoomType){
		return roomStatisticsManager.queryByTypeDetails(startDate,endDate,pkRoomType);
	}
	
	@RequestMapping("/api/roomregister/savenew")
	@ResponseBody
	public RoomRegisterListView saveNewRoomRegister(@ModelAttribute RoomRegisterListView cond){
		return roomRegisterM.saveNewRoomRegister(cond);
	}
	
	@RequestMapping("/api/roomregister/printroom")
	@ResponseBody
	public List<RoomRegisterListView> printRoom(@RequestParam(value="pkServicePoint",required=false)Long pkServicePoint){
		return roomRegisterM.printRoom(pkServicePoint);
	}
	
	@RequestMapping("/api/roomregister/querybypkroom")
	@ResponseBody
	public RoomView queryByPkRoom(@RequestParam(value="pkRoom",required=false)Long pkRoom){
		return roomRegisterM.queryByPkRoom(pkRoom);
	}
	
}